package com.karaku.karaku_collector.common.http;

/**
 * Created by guoping on 2017/4/24.
 */

public class NetError {

    public static final int TYPE_NET = 0;
    public static final int TYPE_HTTP = 1;
    public static final int TYPE_PARSE = 2;
    public static final int TYPE_CANCEL = 4;
    public static final int TYPE_LOGIC = 5;

    public int type;
    public int code;
    public String msg;

    public boolean isLogicError() {
        return type == TYPE_LOGIC;
    }

    public boolean isCanceled() {
        return type == TYPE_CANCEL;
    }

    @Override
    public String toString() {
        if (isLogicError()) {
            return String.format("code:%d, msg:%s", code, msg);
        } else if (type == TYPE_HTTP) {
            return String.format("http error code:%d", code);
        } else if (type == TYPE_PARSE) {
            return "Json解析错误";
        } else if (type == TYPE_NET) {
            return "网络错误";
        }
        return "";
//        if (isLogicError()) {
//            return msg;
//        } else if(type != TYPE_CANCEL) {
//            return "网络请求失败, 请稍候重试!";
//        } else {
//            return "";
//        }
    }
}
